<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="models.Course"%>
<%@page import="models.User"%>
<%@page import="service.UserDao"%>
<%@page import="org.hibernate.Session"%>
<%@page import="service.HibernateUtil"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link href="style/tutor.css" type="text/css" rel="Stylesheet">
        <!-- include jQuery Library From Google Code -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function(){
                function displayValue(){
                    var name = $("#categoryList option:selected").text();
                    var id = $("#categoryList").val();
                    //vul textbox met selected category naam
                    $("#categoryName").val(name);
                    $("#idCat").val(id);
                    $("#id2delete").val(id);
                }
                $("select").change(displayValue);
            });
        </script>

        <jsp:useBean id="inhoud" scope="application" class="models.Bean" />   
        <jsp:setProperty name="inhoud" property="language" value="<%= models.Bean.getLanguage()%>" />

        <title>
            Three 2 Learn
        </title>
    </head>
    <body>       
        <div id="wrapper">
            <jsp:include page="adminSidebar.jsp"/>
            <div id="right">      
                <h1>
                    <jsp:setProperty name="inhoud" property="key" value="ManageCategories" />
                    <jsp:getProperty name="inhoud" property="key" />
                </h1>
                <h2>
                    <jsp:setProperty name="inhoud" property="key" value="AvailableCategories" />
                    <jsp:getProperty name="inhoud" property="key" />
                </h2>
                <div class="box">                
                    <select id="categoryList" multiple="multiple" style="width:240px; height:140px">
                        <c:choose>
                            <c:when test="${not empty categories}">
                                <c:forEach var="tempCategory" items="${categories}">
                                    <option value="${tempCategory.categoryID}">${tempCategory.name}</option>
                                </c:forEach>
                            </c:when>
                        </c:choose>
                    </select>
                </div>
                <div class="box">

                    <table >
                        <form action="/category" method="post">
                            <th colspan="3">
                                <jsp:setProperty name="inhoud" property="key" value="AvailableCategories" />
                                <jsp:getProperty name="inhoud" property="key" />
                            </th>
                            <tr> <td>
                                    <jsp:setProperty name="inhoud" property="key" value="CategoryName" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input required="required"type="text" id="newCat" size="50px" name="newCat"/></td><td><input type="submit" value="Add"> </tr> 
                        </form>       
                    </table>

                    <table >
                        <form action="/category" method="post">
                            <th colspan="3">
                                <jsp:setProperty name="inhoud" property="key" value="EditCategory" />
                                <jsp:getProperty name="inhoud" property="key" />
                            </th>
                            <tr class="darker">
                                <td colspan="3"><p>
                                        <jsp:setProperty name="inhoud" property="key" value="CourseIntro" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                    </p> </td>
                            </tr>
                            <tr> <td>
                                    <jsp:setProperty name="inhoud" property="key" value="CategoryName" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                    :</td><td><input required="required" id="categoryName" size="50px"name="newCat" type="text"/></td><td><input type="submit" value="Edit"></td> </tr>
                            <input type="hidden" id="idCat" name="idCat">
                        </form>
                        <tr> 
                            <td colspan="3">
                                <form method="post" action="/category">
                                    <input type="hidden" id="id2delete" name="id2delete">
                                <input type="submit" value="Delete"/>
                                </form>
                            </td>
                        </tr>        
                    </table>
                </div>
            </div>
        </div>
    </body>
</html>